<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>GtkDrawingArea</title>
<meta name="generator" content="DocBook XSL Stylesheets V1.76.1">
<link rel="home" href="index.html" title="GTK+ 3 参考手册">
<link rel="up" href="MiscObjects.html" title="杂项">
<link rel="prev" href="gtk3-GtkCalendar.html" title="GtkCalendar">
<link rel="next" href="gtk3-GtkEventBox.html" title="GtkEventBox">
<meta name="generator" content="GTK-Doc V1.18 (XML mode)">
<link rel="stylesheet" href="style.css" type="text/css">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<table class="navigation" id="top" width="100%" summary="Navigation header" cellpadding="2" cellspacing="2">
<tr valign="middle">
<td><a accesskey="p" href="gtk3-GtkCalendar.html"><img src="left.png" width="24" height="24" border="0" alt="Prev"></a></td>
<td><a accesskey="u" href="MiscObjects.html"><img src="up.png" width="24" height="24" border="0" alt="Up"></a></td>
<td><a accesskey="h" href="index.html"><img src="home.png" width="24" height="24" border="0" alt="Home"></a></td>
<th width="100%" align="center">GTK+ 3 参考手册</th>
<td><a accesskey="n" href="gtk3-GtkEventBox.html"><img src="right.png" width="24" height="24" border="0" alt="Next"></a></td>
</tr>
<tr><td colspan="5" class="shortcuts">
<a href="#gtk3-GtkDrawingArea.synopsis" class="shortcut">Top</a>
                   | 
                  <a href="#gtk3-GtkDrawingArea.description" class="shortcut">Description</a>
</td></tr>
</table>
<div class="refentry">
<a name="gtk3-GtkDrawingArea"></a><div class="titlepage"></div>
<div class="refnamediv"><table width="100%"><tr>
<td valign="top">
<h2><span class="refentrytitle"><a name="gtk3-GtkDrawingArea.top_of_page"></a>GtkDrawingArea</span></h2>
<p>GtkDrawingArea — A widget for custom user interface elements</p>
</td>
<td valign="top" align="right"></td>
</tr></table></div>
<div class="refsynopsisdiv">
<a name="gtk3-GtkDrawingArea.synopsis"></a><h2>Synopsis</h2>
<pre class="synopsis">
#include &lt;gtk/gtk.h&gt;

struct              <a class="link" href="gtk3-GtkDrawingArea.html#GtkDrawingArea" title="struct GtkDrawingArea">GtkDrawingArea</a>;
<a class="link" href="gtk3-GtkWidget.html#GtkWidget" title="GtkWidget"><span class="returnvalue">GtkWidget</span></a> *         <a class="link" href="gtk3-GtkDrawingArea.html#gtk-drawing-area-new" title="gtk_drawing_area_new ()">gtk_drawing_area_new</a>                (<em class="parameter"><code><span class="type">void</span></code></em>);
</pre>
</div>
<div class="refsect1">
<a name="gtk3-GtkDrawingArea.description"></a><h2>Description</h2>
<p>
The <a class="link" href="gtk3-GtkDrawingArea.html#GtkDrawingArea" title="struct GtkDrawingArea"><span class="type">GtkDrawingArea</span></a> widget is used for creating custom user interface
elements. It's essentially a blank widget; you can draw on it. After
creating a drawing area, the application may want to connect to:
</p>
<p>
</p>
<div class="itemizedlist"><ul class="itemizedlist" type="disc">
<li class="listitem"><p>
    Mouse and button press signals to respond to input from
    the user. (Use <a class="link" href="gtk3-GtkWidget.html#gtk-widget-add-events" title="gtk_widget_add_events ()"><code class="function">gtk_widget_add_events()</code></a> to enable events
    you wish to receive.)
    </p></li>
<li class="listitem"><p>
    The <span class="type">"realize"</span> signal to take any necessary actions
    when the widget is instantiated on a particular display.
    (Create GDK resources in response to this signal.)
    </p></li>
<li class="listitem"><p>
    The <span class="type">"configure-event"</span> signal to take any necessary
    actions when the widget changes size.
    </p></li>
<li class="listitem"><p>
    The <span class="type">"draw"</span> signal to handle redrawing the
    contents of the widget.
    </p></li>
</ul></div>
<p>
</p>
<p>
The following code portion demonstrates using a drawing
area to display a circle in the normal widget foreground
color.
</p>
<p>
Note that GDK automatically clears the exposed area to the
background color before sending the expose event, and that
drawing is implicitly clipped to the exposed area.
</p>
<p>
</p>
<div class="example">
<a name="id3772801"></a><p class="title"><b>Example 81. Simple GtkDrawingArea usage</b></p>
<div class="example-contents"><pre class="programlisting">
gboolean
draw_callback (GtkWidget *widget, cairo_t *cr, gpointer data)
{
  guint width, height;
  GdkRGBA color;

  width = gtk_widget_get_allocated_width (widget);
  height = gtk_widget_get_allocated_height (widget);
  cairo_arc (cr,
             width / 2.0, height / 2.0,
             MIN (width, height) / 2.0,
             0, 2 * G_PI);

  gtk_style_context_get_color (gtk_widget_get_style_context (widget),
                               0,
                               &amp;color);
  gdk_cairo_set_source_rgba (cr, &amp;color);

  cairo_fill (cr);

 return FALSE;
}
[...]
  GtkWidget *drawing_area = gtk_drawing_area_new ();
  gtk_widget_set_size_request (drawing_area, 100, 100);
  g_signal_connect (G_OBJECT (drawing_area), "draw",
                    G_CALLBACK (draw_callback), NULL);
</pre></div>
</div>
<p><br class="example-break">
</p>
<p>
Draw signals are normally delivered when a drawing area first comes
onscreen, or when it's covered by another window and then uncovered.
You can also force an expose event by adding to the "damage region"
of the drawing area's window; <a class="link" href="gtk3-GtkWidget.html#gtk-widget-queue-draw-area" title="gtk_widget_queue_draw_area ()"><code class="function">gtk_widget_queue_draw_area()</code></a> and
<a href="../gdk3/gdk3-Windows.html#gdk-window-invalidate-rect"><code class="function">gdk_window_invalidate_rect()</code></a> are equally good ways to do this.
You'll then get a draw signal for the invalid region.
</p>
<p>
The available routines for drawing are documented on the <a href="../gdk3/gdk3-Cairo-Interaction.html">GDK Drawing Primitives</a> page
and the cairo documentation.
</p>
<p>
To receive mouse events on a drawing area, you will need to enable
them with <a class="link" href="gtk3-GtkWidget.html#gtk-widget-add-events" title="gtk_widget_add_events ()"><code class="function">gtk_widget_add_events()</code></a>. To receive keyboard events, you
will need to set the "can-focus" property on the drawing area, and you
should probably draw some user-visible indication that the drawing
area is focused. Use <a class="link" href="gtk3-GtkWidget.html#gtk-widget-has-focus" title="gtk_widget_has_focus ()"><code class="function">gtk_widget_has_focus()</code></a> in your expose event
handler to decide whether to draw the focus indicator. See
<a class="link" href="gtk3-GtkStyleContext.html#gtk-render-focus" title="gtk_render_focus ()"><code class="function">gtk_render_focus()</code></a> for one way to draw focus.
</p>
</div>
<div class="refsect1">
<a name="gtk3-GtkDrawingArea.details"></a><h2>Details</h2>
<div class="refsect2">
<a name="GtkDrawingArea"></a><h3>struct GtkDrawingArea</h3>
<pre class="programlisting">struct GtkDrawingArea {
  GtkWidget widget;
};
</pre>
<p>
</p>
</div>
<hr>
<div class="refsect2">
<a name="gtk-drawing-area-new"></a><h3>gtk_drawing_area_new ()</h3>
<pre class="programlisting"><a class="link" href="gtk3-GtkWidget.html#GtkWidget" title="GtkWidget"><span class="returnvalue">GtkWidget</span></a> *         gtk_drawing_area_new                (<em class="parameter"><code><span class="type">void</span></code></em>);</pre>
<p>
Creates a new drawing area.
</p>
<div class="variablelist"><table border="0">
<col align="left" valign="top">
<tbody><tr>
<td><p><span class="term"><span class="emphasis"><em>Returns</em></span> :</span></p></td>
<td>a new <a class="link" href="gtk3-GtkDrawingArea.html#GtkDrawingArea" title="struct GtkDrawingArea"><span class="type">GtkDrawingArea</span></a>
</td>
</tr></tbody>
</table></div>
</div>
</div>
<div class="refsect1">
<a name="gtk3-GtkDrawingArea.see-also"></a><h2>See Also</h2>
<a class="link" href="gtk3-GtkImage.html#GtkImage" title="struct GtkImage"><span class="type">GtkImage</span></a>
</div>
</div>
<div class="footer">
<hr>
          Generated by GTK-Doc V1.18</div>
</body>
</html>